<template>
  <div v-loading="loading" class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('合规自查') }}</span>
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('是否公开募资')">
            <el-radio-group v-model="form.openFund">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否保底保息')">
            <el-radio-group v-model="form.guaranteedInterest">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否向不合格投资者募集')">
            <el-radio-group v-model="form.unqualifiedInvestorRaising">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('管理人是否登记')">
            <el-radio-group v-model="form.adminRegister">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('基金是否备案')">
            <el-radio-group v-model="form.fundRegister">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否对投资者的风险识别能力和风险承担能力进行评估')">
            <el-radio-group v-model="form.abilityAssess">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否按照规定保存资料')">
            <el-radio-group v-model="form.saveData">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否按照规定报送信息、披露信息')">
            <el-radio-group v-model="form.infoDisclosure">
              <el-radio
                v-for="dict in yesOrNoOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >{{ $t(dict.dictLabel) }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('基金募集规模情况')" prop="fundRaisingScale">
            <el-input v-model="form.fundRaisingScale" type="textarea" :placeholder="$t('基金募集规模情况')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit :maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('基金设立审批要求')" prop="subjectAsk">
            <el-input v-model="form.subjectAsk" type="textarea" :placeholder="$t('基金设立审批要求')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit :maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('其它说明')" prop="otherExplain">
            <el-input v-model="form.otherExplain" type="textarea" :placeholder="$t('其它说明')" :autosize="{minRows: 3, maxRows: 20}" show-word-limit :maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit :maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="fund_compliance_check" :business-id="autoBusinessId($route.query.id, form)" :btn-show="!otherBtnHide" />
    </el-form>
    <div v-show="!btnHide" slot="footer" class="dialog-footer" style="text-align: center;margin-top: 20px">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <SaveBtn has-permi="fund:check" :cancel-show="false" />
    </div>
  </div>
</template>

<script>
    import { saveFundComplianceCheck, getFundCheckByFundId } from '@/api/fund/check/fundComplianceCheck'
    export default {
        data() {
            return {
                otherBtnHide: false,
                // 是否公开募资字典
                yesOrNoOptions: [], // 是否保底保息字典
                form: {
                  fileList: []
                },
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {},
                // 是否隐藏保存等按钮
                btnHide: false
            }
        },
        mounted() {
          this.$bus.$emit('async_done')
        },
        created() {
            this.getDicts('sys_yes_no').then(response => {
                this.yesOrNoOptions = response.data
            })
        },
        methods: {
            // 初始化数据
            init(data) {
              this.loading = true
              if (data instanceof Object) {
                if (data != null && data.id !== null) {
                  getFundCheckByFundId(data.id).then(response => {
                    console.log(response.data)
                    if (response.data != null) {
                      this.form = response.data
                    } else {
                      this.reset()
                    }
                    this.loading = false
                  })
                } else {
                  this.reset()
                }
              } else {
                if (data != null) {
                  getFundCheckByFundId(data).then(response => {
                    console.log(response.data)
                    if (response.data != null) {
                      this.form = response.data
                    } else {
                      this.reset()
                    }
                    this.loading = false
                  })
                } else {
                  this.reset()
                }
              }
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                fundId: this.$route.query.id,
                openFund: undefined,
                guaranteedInterest: undefined,
                unqualifiedInvestorRaising: undefined,
                adminRegister: undefined,
                fundRegister: undefined,
                abilityAssess: undefined,
                saveData: undefined,
                infoDisclosure: undefined,
                fundRaisingScale: undefined,
                subjectAsk: undefined,
                otherExplain: undefined,
                fileList: [],
                remark: undefined,
                createBy: undefined,
                createTime: undefined,
                updateBy: undefined,
                updateTime: undefined,
                delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveFundComplianceCheck(this.form).then(response => {
                            if (response.code === 200) {
                              this.form.id = response.data.id
                              this.msgSuccess(this.$t('保存成功'))
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        }).catch(() => {
                          this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
